﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using Hjp.FrameWork.Common;
using Wjtour.BLL;
using Wjtour.Common;

namespace Wjtour.Ajax
{
    public class GetGalleryPictures : IHttpHandler
    {
        private int page = 1;
        private int pagesize = 8;

        sitepicture_bll _bll = new sitepicture_bll();
        protected PaginationData<Wjtour.Domain.dto.sitepicture_picturetype> data = new PaginationData<Domain.dto.sitepicture_picturetype>();
        private int type = 0;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            page = Utils.StrToInt(context.Request["page"], 1);
            type = Utils.StrToInt(context.Request["type"], 1);
            data = _bll.GetCoverList(type.ToString(), page - 1, pagesize);

            StringBuilder sb = new StringBuilder();
            if (data != null && data.Datas.Count > 0)
            {
                foreach (var item in data.Datas)
                {
                    sb.AppendLine("<div class=\"item\">");
                    sb.AppendLine("<img src=\"" + item.smallImg + "\" />");
                    sb.AppendLine("<a href=\"galleryshow.aspx?id=" + item.galleryid + "\" target=\"_blank\">");
                    sb.AppendLine(item.galleryname ?? "");
                    sb.AppendLine("</a>");
                    sb.AppendLine("<span class='ding'>");
                    sb.AppendLine("<a href='javascript:void(0)' data-imgid='" + item.id + "'>赞</a>");
                    sb.AppendLine("<span class='num' data-imgid='" + item.id + "'>" + item.zan + "</span>");
                    sb.AppendLine("</span>");
                    sb.AppendLine("</div>");
                }
            }

            context.Response.Write(sb.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
